//=============================================================================
/**
 *
 *	@file		museum_trainer.c
 *	@brief		ポケスロン トレーナーレコード画面
 *	@author		hosaka genya
 *	@data		2008.08.19
 *
 */
//=============================================================================
#include "common.h"
#include "gflib/touchpanel.h"
#include "system/procsys.h"
#include "system/arc_util.h"
#include "system/arc_tool.h"
#include "system/brightness.h"
#include "system/bmp_list.h"
#include "system/bmp_menu.h"
#include "system/window.h"
#include "system/pm_str.h"
#include "system/msgdata.h"
#include "system/wordset.h"
#include "system/fontproc.h"
#include "system/snd_tool.h"
#include "system/clact_util.h"
#include "system/clact_tool.h"
#include "system/render_oam.h"
#include "system/gra_tool.h"
#include "system/palanm.h"
#include "system/wipe.h"
#include "poketool/poke_tool.h"
#include "poketool/pokeicon.h"
#include "msgdata/msg.naix"
#include "msgdata/msg_pokethlon_museum.h"

#include "application/app_tool.h"
#include "application/museum.h"

#include "museum_util.h"
#include "museum_obj.h"
#include "museum_bg.h"

#include "system/pm_overlay.h"

#include "pkth_museum.naix"

FS_EXTERN_OVERLAY(pkthln_common);

//=============================================================================
/**
 *								定数定義
 */
//=============================================================================

//--------------------------------------------------------------
///	BG関係のENUM
//==============================================================
enum
{
	BMPWIN_M_CGX = 1,
	BMPWIN_S_CGX = 1,
	FRM_M_BASE	= GF_BGL_FRAME0_M,
	FRM_M_TEXT	= GF_BGL_FRAME1_M,
	FRM_S_BASE	= GF_BGL_FRAME0_S,
	FRM_S_TEXT	= GF_BGL_FRAME1_S,
};

//--------------------------------------------------------------
///	OBJ_ID
//==============================================================
enum {
	OBJ_MATER_NUM = 10,	///< トロフィーメーターのメモリ数
	OBJ_M_NUM_FIG = 2,
	OBJ_S_NUM_FIG = 4,
};

enum {
	// -- Main LCD --
	OBJ_ID_TRAINER = 0,
	OBJ_ID_COMMON_MAX,

	OBJ_ID_M_NUM_HEAD = OBJ_ID_COMMON_MAX,
	OBJ_ID_S_NUM_HEAD = OBJ_ID_M_NUM_HEAD + OBJ_M_NUM_FIG,

	OBJ_ID_MATER_A_HEAD = OBJ_ID_S_NUM_HEAD + OBJ_S_NUM_FIG,
	OBJ_ID_MATER_B_HEAD = OBJ_ID_MATER_A_HEAD + OBJ_MATER_NUM,
	OBJ_ID_MATER_C_HEAD = OBJ_ID_MATER_B_HEAD + OBJ_MATER_NUM,
	OBJ_ID_MATER_D_HEAD = OBJ_ID_MATER_C_HEAD + OBJ_MATER_NUM,
	OBJ_ID_MATER_TOTAL_HEAD = OBJ_ID_MATER_D_HEAD + OBJ_MATER_NUM,
	OBJ_ID_S_TOTAL_SCORE_MATER_HEAD = OBJ_ID_MATER_TOTAL_HEAD + OBJ_MATER_NUM,
	OBJ_ID_MAX = OBJ_ID_S_TOTAL_SCORE_MATER_HEAD + OBJ_MATER_NUM,
};

//--------------------------------------------------------------
///	OBJ用：リソースID
//==============================================================
enum {
	CHR_ID_M_TRAINER = 0,
	CHR_ID_M_TROPHY,
	CHR_ID_M_NUM,
	CHR_ID_S_TROPHY,
	CHR_ID_S_NUM,
	CHR_ID_MAX,
};

enum {
	PAL_ID_M_TRAINER = 0,
	PAL_ID_M_TROPHY,
	PAL_ID_M_NUM,
	PAL_ID_S_TROPHY,
	PAL_ID_S_NUM,
	PAL_ID_MAX,
};

enum {
	CEL_ID_TRAINER = 0,
	CEL_ID_NUM,
	CEL_ID_TROPHY,
	CEL_ID_MAX,
};

enum {
	ANM_ID_TRAINER = 0,
	ANM_ID_NUM,
	ANM_ID_TROPHY,
	ANM_ID_MAX
};

//--------------------------------------------------------------
///	BMPWIN用IDX
//==============================================================
enum
{
	// Main LCD
	BMPWIN_ID_TRNAME = 0,
	BMPWIN_ID_TROPHY_A,
	BMPWIN_ID_TROPHY_B,
	BMPWIN_ID_TROPHY_C,
	BMPWIN_ID_TROPHY_D,
	BMPWIN_ID_TROPHY_CAP,
	BMPWIN_ID_TRRNK ,
	BMPWIN_ID_RET_CAP,
	// Sub LCD
	BMPWIN_ID_S_SCR_CAP,
	BMPWIN_ID_S_SCR_TAR,
	BMPWIN_ID_S_SCR_CRS,
	BMPWIN_ID_S_SCR_EV,
	BMPWIN_ID_S_SCR_MDL,
	BMPWIN_ID_S_SCR_ALL,
	BMPWIN_ID_S_TEN_CAP,
	BMPWIN_ID_MAX,
};


//=============================================================================
/**
 *								構造体定義
 */
//=============================================================================

//--------------------------------------------------------------
///	モジュール上で参照しか行わないデータ
//==============================================================
typedef struct {
	const MYSTATUS*	p_st;
	u16 total_score_crs;
	u16 total_score_ev;
	u16 total_score_all;
	u16 total_pokemon_mdl;
	u16 crs_score[ ALONE_COURSE_NUM ];
	u8	mdlst_poke_cnt;
	u8	ev_trophy_cnt;
	u8	trsex;
} CONST_DATA;

//--------------------------------------------------------------
///	メインワーク
//==============================================================
typedef struct {
	const CONST_DATA* wk_con;
	GF_BGL_INI*		p_bgl;
	ARCHANDLE*		p_arc_pkth_museum;
	HEAPID			heapID;

	MUSEUM_MSG_WORK*	wk_msg;
	MUSEUM_OBJ_WORK*	wk_obj;
	CATS_ACT_PTR	cap[ OBJ_ID_MAX ];
} MUSEUM_TR_WORK;

//=============================================================================
/**
 *								データテーブル
 */
//=============================================================================

// -- 使用するBGテーブル
enum { BG_USE_NUM = 4, };
static const u8 c_BG_UseList[ BG_USE_NUM ] = {
	GF_BGL_FRAME0_M, GF_BGL_FRAME1_M,
	GF_BGL_FRAME0_S, GF_BGL_FRAME1_S,
};

#define BMP_STRING_H ( 2 )
#define BMP_STRING_LONG_H ( 6 )

//-- main
#define BMP_TRNAME_W	( 24 )
#define BMP_TROPHY_A_W	( 16 )
#define BMP_TROPHY_B_W	( 16 )
#define BMP_TROPHY_C_W	( 16 )
#define BMP_TROPHY_D_W	( 16 )
#define BMP_TROPHY_CAP_W	( 8 )
#define BMP_TRRNK_W		( 22 )
#define BMP_RET_CAP_W	( 6 )
//-- main cgx
#define BMP_TRNAME_CGX		( BMPWIN_M_CGX )
#define BMP_TROPHY_A_CGX	( BMP_TRNAME_CGX	+ BMP_TRNAME_W		* BMP_STRING_H )
#define BMP_TROPHY_B_CGX	( BMP_TROPHY_A_CGX	+ BMP_TROPHY_A_W	* BMP_STRING_H )
#define BMP_TROPHY_C_CGX	( BMP_TROPHY_B_CGX	+ BMP_TROPHY_B_W	* BMP_STRING_H )
#define BMP_TROPHY_D_CGX	( BMP_TROPHY_C_CGX	+ BMP_TROPHY_C_W	* BMP_STRING_H )
#define BMP_TROPHY_CAP_CGX	( BMP_TROPHY_D_CGX	+ BMP_TROPHY_D_W	* BMP_STRING_H )
#define BMP_TRRNK_CGX		( BMP_TROPHY_CAP_CGX+ BMP_TROPHY_CAP_W	* BMP_STRING_H )
#define BMP_RET_CAP_CGX		( BMP_TRRNK_CGX		+ BMP_TRRNK_W		* BMP_STRING_LONG_H )

//-- sub
#define BMP_S_SCR_CAP_W		( 20 )
#define BMP_S_SCR_TAR_W		( 30 )
#define BMP_S_SCR_CRS_W		( 31 )
#define BMP_S_SCR_EV_W		( 31 )
#define BMP_S_SCR_MDL_W		( 30 )
#define BMP_S_SCR_ALL_W		( 10 )
#define BMP_S_TEN_CAP_W		( 8 )
//-- sub cgx
#define BMP_S_SCR_CAP_CGX	( BMPWIN_S_CGX )
#define BMP_S_SCR_TAR_CGX	( BMP_S_SCR_CAP_CGX		+ BMP_S_SCR_CAP_W	* BMP_STRING_H )
#define BMP_S_SCR_CRS_CGX	( BMP_S_SCR_TAR_CGX		+ BMP_S_SCR_TAR_W	* BMP_STRING_H )
#define BMP_S_SCR_EV_CGX	( BMP_S_SCR_CRS_CGX		+ BMP_S_SCR_CRS_W	* BMP_STRING_H )
#define BMP_S_SCR_MDL_CGX	( BMP_S_SCR_EV_CGX		+ BMP_S_SCR_EV_W	* BMP_STRING_H )
#define BMP_S_SCR_ALL_CGX	( BMP_S_SCR_MDL_CGX		+ BMP_S_SCR_MDL_W	* BMP_STRING_H )
#define BMP_S_TEN_CAP_CGX	( BMP_S_SCR_ALL_CGX		+ BMP_S_SCR_ALL_W	* BMP_STRING_H )

//--------------------------------------------------------------
///	BMPWIN用 データテーブル
//==============================================================
static const BMPWIN_DAT c_BmpWinList[ BMPWIN_ID_MAX ] =
{
	// -- main --
	{ FRM_M_TEXT, 0,	0,	BMP_TRNAME_W,		BMP_STRING_H, FONT_TALK_PAL, BMP_TRNAME_CGX, },		// BMPWIN_ID_TRNAME
	{ FRM_M_TEXT, 1,	2,	BMP_TROPHY_A_W,		BMP_STRING_H, FONT_TALK_PAL, BMP_TROPHY_A_CGX, },	// BMPWIN_ID_TROPHY_A
	{ FRM_M_TEXT, 1,	6,	BMP_TROPHY_B_W,		BMP_STRING_H, FONT_TALK_PAL, BMP_TROPHY_B_CGX, },	// BMPWIN_ID_TROPHY_B
	{ FRM_M_TEXT, 1,	10,	BMP_TROPHY_C_W,		BMP_STRING_H, FONT_TALK_PAL, BMP_TROPHY_C_CGX, },	// BMPWIN_ID_TROPHY_C
	{ FRM_M_TEXT, 1,	14,	BMP_TROPHY_D_W,		BMP_STRING_H, FONT_TALK_PAL, BMP_TROPHY_D_CGX, },	// BMPWIN_ID_TROPHY_D
	{ FRM_M_TEXT, 24,	18,	BMP_TROPHY_CAP_W,	BMP_STRING_H, FONT_TALK_PAL, BMP_TROPHY_CAP_CGX, },	// BMPWIN_ID_TROPHY_CAP
	{ FRM_M_TEXT, 1,	18,	BMP_TRRNK_W,		BMP_STRING_LONG_H,	FONT_TALK_PAL, BMP_TRRNK_CGX, },// BMPWIN_ID_TRRNK
	{ FRM_M_TEXT, 26,	21,	BMP_RET_CAP_W,		BMP_STRING_H, FONT_TALK_PAL, BMP_RET_CAP_CGX, },	// BMPWIN_ID_RET_CAP
	// -- sub --
	{ FRM_S_TEXT, 1,	0,	BMP_S_SCR_CAP_W,	BMP_STRING_H, FONT_TALK_PAL, BMP_S_SCR_CAP_CGX, },	// BMPWIN_ID_S_SCR_CAP
	{ FRM_S_TEXT, 1,	2,	BMP_S_SCR_TAR_W,	BMP_STRING_H, FONT_TALK_PAL, BMP_S_SCR_TAR_CGX, },	// BMPWIN_ID_S_SCR_TAR
	{ FRM_S_TEXT, 1,	5,	BMP_S_SCR_CRS_W,	BMP_STRING_H, FONT_TALK_PAL, BMP_S_SCR_CRS_CGX, },	// BMPWIN_ID_S_SCR_CRS
	{ FRM_S_TEXT, 1,	8,	BMP_S_SCR_EV_W,		BMP_STRING_H, FONT_TALK_PAL, BMP_S_SCR_EV_CGX, },	// BMPWIN_ID_S_SCR_EV
	{ FRM_S_TEXT, 1,	11,	BMP_S_SCR_MDL_W,	BMP_STRING_H, FONT_TALK_PAL, BMP_S_SCR_MDL_CGX, },	// BMPWIN_ID_S_SCR_MDL
	{ FRM_S_TEXT, 3,	14,	BMP_S_SCR_ALL_W,	BMP_STRING_H, FONT_TALK_PAL, BMP_S_SCR_ALL_CGX, },	// BMPWIN_ID_S_SCR_ALL
	{ FRM_S_TEXT, 24,	22,	BMP_S_TEN_CAP_W,	BMP_STRING_H, FONT_TALK_PAL, BMP_S_TEN_CAP_CGX, },	// BMPWIN_ID_S_TEN_CAP
};


//=============================================================================
/**
 *							プロトタイプ宣言
 */
//=============================================================================
// -- prototype --
PROC_RESULT MuseumTrainerProc_Init( PROC *proc, int *seq);
PROC_RESULT MuseumTrainerProc_End( PROC *proc,int *seq);
PROC_RESULT MuseumTrainerProc_Main( PROC *proc,int *seq);
static void COMMON_VBlank( void* work );
static void BG_Init( MUSEUM_TR_WORK* wk );
static void BG_LoadRes( MUSEUM_TR_WORK* wk );
static void BG_Release( MUSEUM_TR_WORK* wk );
static void OBJ_LoadRes( MUSEUM_TR_WORK* wk );
static void OBJ_AddCommon( MUSEUM_TR_WORK* wk );
static void OBJ_AddNum( MUSEUM_TR_WORK* wk, u32 num, u32 head_idx, u8 fig, s16 def_x, s16 def_y, u8 diff_x, BOOL b_mainLCD );
static void PRINT_TrainerRank( MUSEUM_TR_WORK* wk, u16 trp_num );
static void PRINT_ScoreTarget( MUSEUM_TR_WORK* wk, u16 trp_num );
static void draw_all_data( MUSEUM_TR_WORK* wk );
static u16 calc_total_event_score( PKTHLN_SV_DATA_PTR p_sv );
static u16 calc_total_pokemon_medal( const u8* p_mdl );
static void CONST_DATA_Create( MUSEUM_TR_WORK*wk, PKTH_MUSEUM_TR_PARAM* p_param );
static void CONST_DATA_Release( const CONST_DATA* wk );
static u8 CONST_DATA_GetEventTrophyCount( const CONST_DATA* wk );
static u8 CONST_DATA_GetMedalistPokemonCount( const CONST_DATA* wk );
static u8 CONST_DATA_GetTrainerSex( const CONST_DATA* wk );
static const MYSTATUS* CONST_DATA_GetMyStatus( const CONST_DATA* wk );
static u16 CONST_DATA_GetTotalMedal( const CONST_DATA* wk );
static u16 CONST_DATA_GetTotalEventScore( const CONST_DATA* wk );
static u16 CONST_DATA_GetTotalCourseScore( const CONST_DATA* wk );
static u16 CONST_DATA_GetTotalScoreAll( const CONST_DATA* wk );
static u16 CONST_DATA_GetCourseScore( const CONST_DATA* wk, u8 crs_idx );
static u8 calc_all_trophy_count( u16 total_score );
static u8 calc_course_trophy_count( MUSEUM_TR_WORK* wk );


//=============================================================================
/**
 *								外部公開関数
 */
//=============================================================================

//==============================================================================
/**
 *	@brief	プロセス初期化
 *	@param	proc	プロセスデータ
 *	@param	seq		シーケンス
 *
 *	@return	処理状況
 */
//==============================================================================
PROC_RESULT MuseumTrainerProc_Init( PROC *proc, int *seq)
{
	MUSEUM_TR_WORK *wk = NULL;
	PKTH_MUSEUM_TR_PARAM * p_param;

	Overlay_Load( FS_OVERLAY_ID(pkthln_common), OVERLAY_LOAD_NOT_SYNCHRONIZE );

	p_param = (PKTH_MUSEUM_TR_PARAM*)PROC_GetParentWork( proc );

	GF_ASSERT( p_param );

	//ヒープ作成
	sys_CreateHeap( HEAPID_BASE_APP, HEAPID_PKTH_MUSEUM, 0x30000 );

	wk = PROC_AllocWork( proc, sizeof(MUSEUM_TR_WORK), HEAPID_PKTH_MUSEUM );
	MI_CpuClear8( wk, sizeof(MUSEUM_TR_WORK) );

	// パラメータ設定
	wk->heapID = HEAPID_PKTH_MUSEUM;

	// コンストデータ生成
	CONST_DATA_Create( wk, p_param );

	// 汎用初期化処理
	MUSEUM_COMMON_Init();

	// BG初期化
	BG_Init( wk );
	BG_LoadRes( wk );
	wk->wk_msg = MUSEUM_BMPWIN_Create( wk->heapID, wk->p_bgl, BMPWIN_ID_MAX, c_BmpWinList, NARC_msg_pokethlon_museum_dat );

	// OBJ初期化
	{
		TCATS_RESOURCE_NUM_LIST crnl = { CHR_ID_MAX, PAL_ID_MAX, CEL_ID_MAX, ANM_ID_MAX, 0 };
		wk->wk_obj = MUSEUM_OBJ_Create( wk->heapID, &crnl, OBJ_ID_MAX );
	}
	OBJ_LoadRes( wk );

	// 描画
	draw_all_data( wk );

	WIPE_ResetWndMask( WIPE_DISP_MAIN );
	WIPE_ResetWndMask( WIPE_DISP_SUB );

	sys_VBlankFuncChange( COMMON_VBlank, wk );

	return PROC_RES_FINISH;

}

//==============================================================================
/**
 *	@brief	プロセス終了
 *	@param	proc	プロセスデータ
 *	@param	seq		シーケンス
 *
 *	@return	処理状況
 */
//==============================================================================
PROC_RESULT MuseumTrainerProc_End( PROC *proc,int *seq)
{
	MUSEUM_TR_WORK* wk = PROC_GetWork( proc );

	//コンストデータ開放
	CONST_DATA_Release( wk->wk_con );

	// -- OBJ
	MUSEUM_OBJ_Delete( wk->wk_obj, wk->cap, OBJ_ID_MAX );

	// -- BG
	MUSEUM_BMPWIN_Delete( wk->wk_msg, BMPWIN_ID_MAX );
	BG_Release( wk );

	// -- COMMON
	MUSEUM_COMMON_Release();

	//ワークエリア解放
	PROC_FreeWork( proc );

	sys_DeleteHeap( HEAPID_PKTH_MUSEUM );

	Overlay_UnloadID( FS_OVERLAY_ID(pkthln_common) );

	return PROC_RES_FINISH;

}

//==============================================================================
/**
 *	@brief	プロセスメイン
 *	@param	proc	プロセスデータ
 *	@param	seq		シーケンス
 *
 *	@return	処理状況
 */
//==============================================================================
PROC_RESULT MuseumTrainerProc_Main( PROC *proc,int *seq)
{
	enum
	{
		MAIN_SEQ_INIT = 0,
		MAIN_SEQ_FADE_IN,
		MAIN_SEQ_MAIN,
		MAIN_SEQ_FADE_OUT,
		MAIN_SEQ_END,
	};

	MUSEUM_TR_WORK* wk = PROC_GetWork(proc);

	switch( *seq )
	{
		case MAIN_SEQ_INIT :
			WIPE_SYS_Start( WIPE_PATTERN_WMS, WIPE_TYPE_FADEIN, WIPE_TYPE_FADEIN,
							0x0000, COMM_BRIGHTNESS_SYNC, 1, wk->heapID );
			(*seq) = MAIN_SEQ_FADE_IN;
			break;

		case MAIN_SEQ_FADE_IN :
			if( WIPE_SYS_EndCheck() )
			{
				(*seq) = MAIN_SEQ_MAIN;
			}
			break;

		case MAIN_SEQ_MAIN :
			if( MUSEUM_UTIL_CheckExit() )
			{
				Snd_SePlay( SEQ_SE_DP_SELECT );

				WIPE_SYS_Start( WIPE_PATTERN_WMS, WIPE_TYPE_FADEOUT, WIPE_TYPE_FADEOUT,
								0x0000, COMM_BRIGHTNESS_SYNC, 1, wk->heapID );
				(*seq) = MAIN_SEQ_FADE_OUT;
			}
			break;

		case MAIN_SEQ_FADE_OUT :
			if( WIPE_SYS_EndCheck() )
			{
				(*seq) = MAIN_SEQ_END;
			}
			break;

		case MAIN_SEQ_END :
			return PROC_RES_FINISH;

		default : GF_ASSERT( !"seq error!" );
	}

	MUSEUM_OBJ_Draw( wk->wk_obj );

	return PROC_RES_CONTINUE;
}

//=============================================================================
/**
 *								static関数
 */
//=============================================================================

//-----------------------------------------------------------------------------
/**
 *	@brief	VBlank処理
 *
 *	@param	* work
 *
 *	@retval	none
 */
//-----------------------------------------------------------------------------
static void COMMON_VBlank( void* work )
{
	MUSEUM_TR_WORK* wk = work;

	CATS_RenderOamTrans();
	GF_BGL_VBlankFunc( wk->p_bgl );
	OS_SetIrqCheckFlag( OS_IE_V_BLANK );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	BG 初期化
 *
 *	@param	MUSEUM_TR_WORK* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void BG_Init( MUSEUM_TR_WORK* wk )
{
	wk->p_bgl = GF_BGL_BglIniAlloc( wk->heapID );

	{	//BG SYSTEM
		GF_BGL_SYS_HEADER BGsys_data = {
			GX_DISPMODE_GRAPHICS,GX_BGMODE_0,GX_BGMODE_0,GX_BG0_AS_2D
		};
		GF_BGL_InitBG(&BGsys_data);
	}

	{
		int i;
		GF_BGL_BGCNT_HEADER TextBgCntDat[ BG_USE_NUM ] = {
			// -- MAIN --
			{	// FRM_M_BASE BG0
				0,0,0x800,0,GF_BGL_SCRSIZ_256x256,GX_BG_COLORMODE_16,
				GX_BG_SCRBASE_0xf800,GX_BG_CHARBASE_0x00000,GX_BG_EXTPLTT_01,
				3,0,0,FALSE
			},
			{	//FRM_M_TEXT BG1
				0,0,0x800,0,GF_BGL_SCRSIZ_256x256,GX_BG_COLORMODE_16,
				GX_BG_SCRBASE_0xf000,GX_BG_CHARBASE_0x04000,GX_BG_EXTPLTT_01,
				0,0,0,FALSE

			},
			// -- SUB --
			{	// FRM_S_BASE BG0
				0,0,0x800,0,GF_BGL_SCRSIZ_256x256,GX_BG_COLORMODE_16,
				GX_BG_SCRBASE_0xf800,GX_BG_CHARBASE_0x00000,GX_BG_EXTPLTT_01,
				3,0,0,FALSE
			},
			{	// FRM_S_TEXT BG1
				0,0,0x800,0,GF_BGL_SCRSIZ_256x256,GX_BG_COLORMODE_16,
				GX_BG_SCRBASE_0xf000,GX_BG_CHARBASE_0x04000,GX_BG_EXTPLTT_01,
				0,0,0,FALSE
			},
		};

		for( i=0; i<BG_USE_NUM; i++ )
		{
			GF_BGL_BGControlSet(wk->p_bgl, c_BG_UseList[i], &(TextBgCntDat[i]), GF_BGL_MODE_TEXT);
			GF_BGL_ScrClear(wk->p_bgl, c_BG_UseList[i]);
			GF_BGL_ClearCharSet(c_BG_UseList[i], 32, 0, wk->heapID);
		}
	}

	wk->p_arc_pkth_museum = ArchiveDataHandleOpen( ARC_PKTH_MUSEUM_GRA, wk->heapID );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	BG リソースロード
 *
 *	@param	MUSEUM_TR_WORK* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void BG_LoadRes( MUSEUM_TR_WORK* wk )
{
	enum { BG_PALSIZE = 0x20 * 2, };

	//----------------------------------------------------
	// Main LCD
	ArcUtil_HDL_PalSet( wk->p_arc_pkth_museum, NARC_pkth_museum_trainer_bg_NCLR, PALTYPE_MAIN_BG,
					0, BG_PALSIZE, wk->heapID );

	// -- base --
	ArcUtil_HDL_BgCharSet( wk->p_arc_pkth_museum, NARC_pkth_museum_trainer_bg_lz_NCGR,
						wk->p_bgl, FRM_M_BASE, 0, 0, TRUE, wk->heapID );
	ArcUtil_HDL_ScrnSet( wk->p_arc_pkth_museum, NARC_pkth_museum_trainer_bg_lz_NSCR,
						wk->p_bgl, FRM_M_BASE, 0, 0, TRUE, wk->heapID );

	//----------------------------------------------------
	// Sub LCD
	ArcUtil_HDL_PalSet( wk->p_arc_pkth_museum, NARC_pkth_museum_trainer_bg_sub_NCLR, PALTYPE_SUB_BG,
					0, BG_PALSIZE, wk->heapID );

	// -- base --
	ArcUtil_HDL_BgCharSet( wk->p_arc_pkth_museum, NARC_pkth_museum_trainer_bg_sub_lz_NCGR,
						wk->p_bgl, FRM_S_BASE, 0, 0, TRUE, wk->heapID );
	ArcUtil_HDL_ScrnSet( wk->p_arc_pkth_museum, NARC_pkth_museum_trainer_bg_sub_lz_NSCR,
						wk->p_bgl, FRM_S_BASE, 0, 0, TRUE, wk->heapID );

}

//-----------------------------------------------------------------------------
/**
 *	@brief	BG 開放
 *
 *	@param	MUSEUM_TR_WORK* wk
 *
 *	@retval	none
 */
//-----------------------------------------------------------------------------
static void BG_Release( MUSEUM_TR_WORK* wk )
{
	u8 i = 0;

	ArchiveDataHandleClose( wk->p_arc_pkth_museum );

	for( i=0; i<BG_USE_NUM; i++ )
	{
		GF_BGL_BGControlExit( wk->p_bgl, c_BG_UseList[i] );
	}

	sys_FreeMemoryEz( wk->p_bgl );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	OBJ リソースロード
 *
 *	@param	MUSEUM_TR_WORK* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void OBJ_LoadRes( MUSEUM_TR_WORK* wk )
{
	CATS_SYS_PTR	csp = MUSEUM_OBJ_GetCsp( wk->wk_obj );
	CATS_RES_PTR	crp = MUSEUM_OBJ_GetCrp( wk->wk_obj );

	// -- trainer_obj --
	CATS_LoadResourceCharArcH( csp, crp, wk->p_arc_pkth_museum,
			NARC_pkth_museum_trainer_obj_lz_NCGR, TRUE, NNS_G2D_VRAM_TYPE_2DMAIN, CHR_ID_M_TRAINER );

	CATS_LoadResourcePlttArcH( csp, crp, wk->p_arc_pkth_museum,
			NARC_pkth_museum_trainer_obj_NCLR, 0, 2, NNS_G2D_VRAM_TYPE_2DMAIN, PAL_ID_M_TRAINER );

	CATS_LoadResourceCellArcH( csp, crp, wk->p_arc_pkth_museum,
			NARC_pkth_museum_trainer_obj_lz_NCER, TRUE, CEL_ID_TRAINER );

	CATS_LoadResourceCellAnmArcH( csp, crp,  wk->p_arc_pkth_museum,
			NARC_pkth_museum_trainer_obj_lz_NANR, TRUE, ANM_ID_TRAINER );

	// -- obj_num_big --
	CATS_LoadResourceCharArcH( csp, crp, wk->p_arc_pkth_museum,
			NARC_pkth_museum_obj_num_big_lz_NCGR, TRUE, NNS_G2D_VRAM_TYPE_2DSUB, CHR_ID_S_NUM );

	CATS_LoadResourcePlttArcH( csp, crp, wk->p_arc_pkth_museum,
			NARC_pkth_museum_obj_num_big_NCLR, 0, 1, NNS_G2D_VRAM_TYPE_2DSUB, PAL_ID_S_NUM );

	CATS_LoadResourceCharArcH( csp, crp, wk->p_arc_pkth_museum,
			NARC_pkth_museum_obj_num_big_lz_NCGR, TRUE, NNS_G2D_VRAM_TYPE_2DMAIN, CHR_ID_M_NUM );

	CATS_LoadResourcePlttArcH( csp, crp, wk->p_arc_pkth_museum,
			NARC_pkth_museum_obj_num_big_NCLR, 0, 1, NNS_G2D_VRAM_TYPE_2DMAIN, PAL_ID_M_NUM );

	CATS_LoadResourceCellArcH( csp, crp, wk->p_arc_pkth_museum,
			NARC_pkth_museum_obj_num_big_lz_NCER, TRUE, CEL_ID_NUM );

	CATS_LoadResourceCellAnmArcH( csp, crp,  wk->p_arc_pkth_museum,
			NARC_pkth_museum_obj_num_big_lz_NANR, TRUE, ANM_ID_NUM );

	// -- obj_trophy --
	CATS_LoadResourceCharArcH( csp, crp, wk->p_arc_pkth_museum,
			NARC_pkth_museum_obj_trophy_lz_NCGR, TRUE, NNS_G2D_VRAM_TYPE_2DMAIN, CHR_ID_M_TROPHY );

	CATS_LoadResourcePlttArcH( csp, crp, wk->p_arc_pkth_museum,
			NARC_pkth_museum_obj_trophy_NCLR, 0, 1, NNS_G2D_VRAM_TYPE_2DMAIN, PAL_ID_M_TROPHY );

	CATS_LoadResourceCharArcH( csp, crp, wk->p_arc_pkth_museum,
			NARC_pkth_museum_obj_trophy_lz_NCGR, TRUE, NNS_G2D_VRAM_TYPE_2DSUB, CHR_ID_S_TROPHY );

	CATS_LoadResourcePlttArcH( csp, crp, wk->p_arc_pkth_museum,
			NARC_pkth_museum_obj_trophy_NCLR, 0, 1, NNS_G2D_VRAM_TYPE_2DSUB, PAL_ID_S_TROPHY );

	CATS_LoadResourceCellArcH( csp, crp, wk->p_arc_pkth_museum,
			NARC_pkth_museum_obj_trophy_lz_NCER, TRUE, CEL_ID_TROPHY );

	CATS_LoadResourceCellAnmArcH( csp, crp,  wk->p_arc_pkth_museum,
			NARC_pkth_museum_obj_trophy_lz_NANR, TRUE, ANM_ID_TROPHY );

}

//-----------------------------------------------------------------------------
/**
 *	@brief	汎用セルアクター追加
 *
 *	@param	MUSEUM_TR_WORK * wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void OBJ_AddCommon( MUSEUM_TR_WORK * wk )
{
	static const TCATS_OBJECT_ADD_PARAM_S	common_prm[ OBJ_ID_COMMON_MAX ] =
	{
		{	// OBJ_ID_TRAINER
			27*8,	5*8,	0,
			0, 2, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
			{ CHR_ID_M_TRAINER, PAL_ID_M_TRAINER, CEL_ID_TRAINER, ANM_ID_TRAINER, 0, 0 }, 0, FALSE,
		},
	};

	int i;

	// COMMON OBJ初期化
	for( i=0; i < OBJ_ID_COMMON_MAX; i++ )
	{
		wk->cap[ i ] = MUSEUM_OBJ_Add( wk->wk_obj, &common_prm[ i ] );
		CATS_ObjectAutoAnimeSetCap( wk->cap[ i ], TRUE );
	};
}

//-----------------------------------------------------------------------------
/**
 *	@brief
 *
 *	@param	MUSEUM_TR_WORK* wk
 *	@param	num
 *	@param	head_idx
 *	@param	fig
 *	@param	def_x
 *	@param	def_y
 *	@param	diff_x
 *	@param	b_mainLCD
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void OBJ_AddNum( MUSEUM_TR_WORK* wk, u32 num, u32 head_idx, u8 fig, s16 def_x, s16 def_y, u8 diff_x, BOOL b_mainLCD )
{
	static const res_tbl_m[] = { CHR_ID_M_NUM, PAL_ID_M_NUM, CEL_ID_NUM, ANM_ID_NUM, 0, 0, };
	static const res_tbl_s[] = { CHR_ID_S_NUM, PAL_ID_S_NUM, CEL_ID_NUM, ANM_ID_NUM, 0, 0, };

	TCATS_OBJECT_ADD_PARAM_S prm = {0};
	u32 i;
	u8 num_fig = UTIL_GetFigure( num );

	for( i=0; i<fig; i++ )
	{
		prm.anm = UTIL_GetFigreAppoint( num, fig-i );
		MI_CpuCopy8( (b_mainLCD ? res_tbl_m : res_tbl_s ), prm.id, sizeof(prm.id) );
		prm.d_area = ( b_mainLCD ? NNS_G2D_VRAM_TYPE_2DMAIN : NNS_G2D_VRAM_TYPE_2DSUB );
		prm.x = def_x + i * diff_x;
		prm.y = def_y;

		wk->cap[ head_idx + i ] = MUSEUM_OBJ_Add( wk->wk_obj, &prm );
		CATS_ObjectAutoAnimeSetCap( wk->cap[ head_idx + i ], TRUE );

		if( fig - num_fig > i ){ CATS_ObjectEnableCap( wk->cap[ head_idx + i ], CATS_ENABLE_FALSE ); }
	}
}

//-----------------------------------------------------------------------------
/**
 *	@brief	トレイナーランクを表示
 *
 *	@param	MUSEUM_TR_WORK* wk
 *	@param	trp_num
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void PRINT_TrainerRank( MUSEUM_TR_WORK* wk, u16 trp_num )
{
	GF_ASSERT( trp_num <= OBJ_MATER_NUM * 4 );
	MUSEUM_BMPWIN_Print( wk->wk_msg, BMPWIN_ID_TRRNK, msg_pkthRNK_trrnk_00 + (trp_num/2), FALSE );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	目的スコアを表示
 *
 *	@param	MUSEUM_TR_WORK* wk
 *	@param	total_trp
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void PRINT_ScoreTarget( MUSEUM_TR_WORK* wk, u16 total_trp )
{
	GF_ASSERT( total_trp <= OBJ_MATER_NUM );
	MUSEUM_BMPWIN_Print( wk->wk_msg, BMPWIN_ID_S_SCR_TAR, msg_pkthRNK_trtrohy_00 + total_trp, FALSE );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	描画処理
 *
 *	@param	MUSEUM_TR_WORK* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void draw_all_data( MUSEUM_TR_WORK* wk )
{
	u16 scr_crs	= CONST_DATA_GetTotalCourseScore( wk->wk_con );
	u16 scr_ev	= CONST_DATA_GetTotalEventScore( wk->wk_con );
	u16 scr_mdl	= CONST_DATA_GetTotalMedal( wk->wk_con );
	u16 scr_all	= CONST_DATA_GetTotalScoreAll( wk->wk_con );
	u8 trsex	= CONST_DATA_GetTrainerSex( wk->wk_con );
	u8 trp_a_num	= calc_course_trophy_count( wk );
	u8 trp_b_num	= MUSEUM_UTIL_GetPokemonTrophyCount( CONST_DATA_GetMedalistPokemonCount( wk->wk_con ) );
	u8 trp_c_num	= CONST_DATA_GetEventTrophyCount( wk->wk_con );
	u8 trp_d_num	= calc_all_trophy_count( scr_all );
	u8 trp_all_num	= trp_a_num + trp_b_num + trp_c_num + trp_d_num;

	//========================================================================
	// BMPWIN
	//========================================================================
	// main
	{
		WORDSET* wset = MUSEUM_BMPWIN_GetWordset( wk->wk_msg );
		WORDSET_RegisterPlayerName( wset, 0, CONST_DATA_GetMyStatus( wk->wk_con ) );
		MUSEUM_BMPWIN_PrintAndSetOfs( wk->wk_msg, BMPWIN_ID_TRNAME, msg_pkthRNK_tr_name, 1, 0 );
	}
	MUSEUM_BMPWIN_Print( wk->wk_msg, BMPWIN_ID_TROPHY_A,	msg_pkthRNK_trtrophy_A, FALSE );
	MUSEUM_BMPWIN_Print( wk->wk_msg, BMPWIN_ID_TROPHY_B,	msg_pkthRNK_trtrophy_B, FALSE );
	MUSEUM_BMPWIN_Print( wk->wk_msg, BMPWIN_ID_TROPHY_C,	msg_pkthRNK_trtrophy_C, FALSE );
	MUSEUM_BMPWIN_Print( wk->wk_msg, BMPWIN_ID_TROPHY_D,	msg_pkthRNK_trtrophy_D, FALSE );
	MUSEUM_BMPWIN_PrintAndSetOfs( wk->wk_msg, BMPWIN_ID_TROPHY_CAP,	msg_pkthRNK_trtrophy_cap, 2, 0 );
	MUSEUM_BMPWIN_PrintEx( wk->wk_msg, BMPWIN_ID_RET_CAP,	msg_pkthRNK_return,	FALSE, 0, FONT_TOUCH );
	PRINT_TrainerRank( wk, trp_all_num );
	// sub
	MUSEUM_BMPWIN_Print(	wk->wk_msg, BMPWIN_ID_S_SCR_CAP,	msg_pkthRNK_trtotal,	FALSE );
	MUSEUM_BMPWIN_Print(	wk->wk_msg,	BMPWIN_ID_S_SCR_ALL,	msg_pkthRNK_trtotalp,	FALSE );
	MUSEUM_BMPWIN_Print(	wk->wk_msg,	BMPWIN_ID_S_TEN_CAP,	msg_pkthRNK_ten_cap,	FALSE );
	MUSEUM_BMPWIN_PrintNum(	wk->wk_msg,	BMPWIN_ID_S_SCR_CRS,	msg_pkthRNK_trcrs,		scr_crs,	4, 0 );
	MUSEUM_BMPWIN_PrintNum(	wk->wk_msg,	BMPWIN_ID_S_SCR_EV,		msg_pkthRNK_trev,		scr_ev,		4, 0 );
	MUSEUM_BMPWIN_PrintNum(	wk->wk_msg,	BMPWIN_ID_S_SCR_MDL,	msg_pkthRNK_trmdl,		scr_mdl,	4, 0 );
	PRINT_ScoreTarget( wk, trp_d_num );

	// 汎用OBJ追加
	OBJ_AddCommon( wk );

	// 男女きりわけ
	if( trsex == PM_FEMALE )
	{
		CATS_ObjectAnimeSeqSetCap( wk->cap[ OBJ_ID_TRAINER ], 1 );
		CATS_ObjectPaletteSetCap( wk->cap[ OBJ_ID_TRAINER ], 1 );
	}

	OBJ_AddNum( wk, trp_all_num, OBJ_ID_M_NUM_HEAD, OBJ_M_NUM_FIG, 25*8, 14*8, 4*8, TRUE );
	OBJ_AddNum( wk, scr_all, OBJ_ID_S_NUM_HEAD, OBJ_S_NUM_FIG, 10*8, 20*8, 4*8, FALSE );

	{
		static const MUSEUM_OBJ_ID objID_M = { CHR_ID_M_TROPHY, PAL_ID_M_TROPHY, CEL_ID_TROPHY, ANM_ID_TROPHY, };
		static const MUSEUM_OBJ_ID objID_S = { CHR_ID_S_TROPHY, PAL_ID_S_TROPHY, CEL_ID_TROPHY, ANM_ID_TROPHY, };

		MUSEUM_OBJ_AddMater( wk->wk_obj, wk->cap, &objID_M, trp_a_num, OBJ_ID_MATER_A_HEAD, 2*8, 5*8, TRUE );
		MUSEUM_OBJ_AddMater( wk->wk_obj, wk->cap, &objID_M, trp_b_num, OBJ_ID_MATER_B_HEAD, 2*8, 9*8, TRUE );
		MUSEUM_OBJ_AddMater( wk->wk_obj, wk->cap, &objID_M, trp_c_num, OBJ_ID_MATER_C_HEAD, 2*8, 13*8, TRUE );
		MUSEUM_OBJ_AddMater( wk->wk_obj, wk->cap, &objID_M, trp_d_num, OBJ_ID_MATER_D_HEAD, 2*8, 17*8, TRUE );
		MUSEUM_OBJ_AddMater( wk->wk_obj, wk->cap, &objID_S, trp_d_num, OBJ_ID_S_TOTAL_SCORE_MATER_HEAD, 12*8, 15*8, FALSE );
	}
}

//-----------------------------------------------------------------------------
/**
 *	@brief	競技スコアの合計を計算
 *
 *	@param	PKTHLN_SV_DATA_PTR p_sv
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static u16 calc_total_event_score( PKTHLN_SV_DATA_PTR p_sv )
{
	u8 i;
	u16 ret = 0;
	u16* p_best_point_tbl_head;

	GF_ASSERT( p_sv );

	p_best_point_tbl_head = PkthlnSv_GetBestRecScore( p_sv );

	for( i=0; i<PKTHLN_EVT_MAX; i++ )
	{
		ret += p_best_point_tbl_head[i];
	}

	return ret;
}

//-----------------------------------------------------------------------------
/**
 *	@brief	ポケモンメダルの合計を計算
 *
 *	@param	const u8* p_mdl
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static u16 calc_total_pokemon_medal( const u8* p_mdl )
{
	int i;
	u16 ret = 0;

	GF_ASSERT( p_mdl );


	for( i=0; i<MONSNO_END; i++ )
	{
		ret += MATH_CountPopulation( p_mdl[i] );
	}

	return ret;
}

//-----------------------------------------------------------------------------
/**
 *	@brief	参照用データ 生成
 *
 *	@param	MUSEUM_TR_WORK*wk
 *	@param	p_param
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void CONST_DATA_Create( MUSEUM_TR_WORK*wk, PKTH_MUSEUM_TR_PARAM* p_param )
{
	int i;
	PKTHLN_SV_DATA_PTR		p_sv = NULL;
	const MYSTATUS*			p_st = NULL;
	const PKTH_COURSE*		p_crs = NULL;
	const PKTH_EVT_DATA*	p_ev = NULL;
	const u8*				p_mdl = NULL;
	CONST_DATA*				cwk = NULL;

	cwk = sys_AllocMemory( wk->heapID, sizeof(CONST_DATA) );
	MI_CpuClear8( cwk, sizeof(CONST_DATA) );

	p_sv = p_param->p_sv;
	p_st = p_param->p_st;

	p_crs = PkthlnSv_GetCrsDataAloneCnst( p_sv );
	p_ev = PkthlnSv_GetEvtDataAloneCnst( p_sv );
	p_mdl = PkthlnSv_GetMedalDataCnst( p_sv );

	for( i=0; i<ALONE_COURSE_NUM; i++ )
	{
		cwk->crs_score[i]	= p_crs[i].MaxScore;
		cwk->total_score_crs += cwk->crs_score[i];
	}

	cwk->p_st				= p_st;
	cwk->total_score_ev		= calc_total_event_score( p_sv );
	cwk->total_pokemon_mdl	= calc_total_pokemon_medal( p_mdl );
	cwk->mdlst_poke_cnt		= MUSEUM_UTIL_GetMedalistPokemonCount( p_mdl );
	cwk->ev_trophy_cnt		= MUSEUM_UTIL_GetEventTrophyCount( p_ev );
	cwk->total_score_all	= cwk->total_score_crs + cwk->total_score_ev + cwk->total_pokemon_mdl;
	cwk->trsex				= MyStatus_GetMySex( p_st );

	wk->wk_con = cwk;
}

//-----------------------------------------------------------------------------
/**
 *	@brief	参照用データ 開放
 *
 *	@param	const CONST_DATA* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void CONST_DATA_Release( const CONST_DATA* wk )
{
	sys_FreeMemoryEz( (CONST_DATA*)wk );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	競技トロフィーの数を取得
 *
 *	@param	const CONST_DATA* wk
 */
//-----------------------------------------------------------------------------
static u8 CONST_DATA_GetEventTrophyCount( const CONST_DATA* wk )
{
	GF_ASSERT( wk );
	return wk->ev_trophy_cnt;
}

//-----------------------------------------------------------------------------
/**
 *	@brief	メダリストポケモンの数を取得
 *
 *	@param	const CONST_DATA* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static u8 CONST_DATA_GetMedalistPokemonCount( const CONST_DATA* wk )
{
	GF_ASSERT( wk );
	return wk->mdlst_poke_cnt;
}

//-----------------------------------------------------------------------------
/**
 *	@brief	トレーナーの性別を取得
 */
//-----------------------------------------------------------------------------
static u8 CONST_DATA_GetTrainerSex( const CONST_DATA* wk )
{
	GF_ASSERT( wk );
	return wk->trsex;
}

//-----------------------------------------------------------------------------
/**
 *	@brief	ステータスへのポインタを取得
 */
//-----------------------------------------------------------------------------
static const MYSTATUS* CONST_DATA_GetMyStatus( const CONST_DATA* wk )
{
	GF_ASSERT( wk );
	return wk->p_st;
}

//-----------------------------------------------------------------------------
/**
 *	@brief	獲得メダルの合計を取得
 */
//-----------------------------------------------------------------------------
static u16 CONST_DATA_GetTotalMedal( const CONST_DATA* wk )
{
	GF_ASSERT( wk );
	return wk->total_pokemon_mdl;
}

//-----------------------------------------------------------------------------
/**
 *	@brief	各競技の一位総合点 取得
 */
//-----------------------------------------------------------------------------
static u16 CONST_DATA_GetTotalEventScore( const CONST_DATA* wk )
{
	GF_ASSERT( wk );
	return wk->total_score_ev;
}

//-----------------------------------------------------------------------------
/**
 *	@brief	コースレコード合計点 取得
 */
//-----------------------------------------------------------------------------
static u16 CONST_DATA_GetTotalCourseScore( const CONST_DATA* wk )
{
	GF_ASSERT( wk );
	return wk->total_score_crs;
}

//-----------------------------------------------------------------------------
/**
 *	@brief	総合点取得
 *
 *	@param	const CONST_DATA* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static u16 CONST_DATA_GetTotalScoreAll( const CONST_DATA* wk )
{
	GF_ASSERT( wk );
	return wk->total_score_all;
}

//-----------------------------------------------------------------------------
/**
 *	@brief	指定コースのスコアを取得
 *
 *	@param	const CONST_DATA* wk
 *	@param	crs_idx
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static u16 CONST_DATA_GetCourseScore( const CONST_DATA* wk, u8 crs_idx )
{
	GF_ASSERT( wk );
	return wk->crs_score[ crs_idx ];
}

//-----------------------------------------------------------------------------
/**
 *	@brief	総合点からトロフィーの数を算出
 *
 *	@param	u16 total_score
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static u8 calc_all_trophy_count( u16 total_score )
{
	static const tbl[] = { 4500, 4200, 4000, 3800, 3600, 3400, 3300, 3200, 3100, 3000,  };
	u8 tbl_max;
	u8 i;

	tbl_max = NELEMS(tbl);

	for(i=0; i<tbl_max; i++)
	{
		if( tbl[i] <= total_score )
		{
			break;
		}
	};

	return tbl_max - i;
}

//-----------------------------------------------------------------------------
/**
 *	@brief	コーストロフィーの数を算出
 *
 *	@param	MUSEUM_TR_WORK* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static u8 calc_course_trophy_count( MUSEUM_TR_WORK* wk )
{
	int i;
	u8 cnt = 0;

	for( i=0; i<ALONE_COURSE_NUM; i++ )
	{
		cnt += MUSEUM_UTIL_GetCourseTrophyCount( CONST_DATA_GetCourseScore( wk->wk_con, i ) );
	}

	return cnt;
}